package org.modulefusion.testrunner;

import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestListener;

import org.osgi.framework.BundleContext;

public class Listener implements TestListener {
	
	private final BundleContext context;

	public Listener(BundleContext context) {
		this.context = context;
	}


	public void addError(Test test, Throwable throwable) {
		testError(test, throwable);
	}


	public void addFailure(Test test, AssertionFailedError error) {
		testError(test, error);
	}

	public void startTest(Test test) {
		System.out.println("TestRunner: " + test);
	}
	
	public void endTest(Test test) {
	}

	private void testError(Test test, Throwable throwable) {
		System.out.println("------------------------------------------------");
		System.out.println("Error in test [" + test + "]");
		System.out.println("------------------------------------------------");
		throwable.printStackTrace(System.out);
		System.out.println("------------------------------------------------");
		System.out.println("TEST FAILURE");
		SystemUtil.exit(true);
	}

}
